import {
    createDiscreteApi
} from "naive-ui";
import axios from "axios";
const { message } = createDiscreteApi(["message", "dialog", "notification", "loadingBar"]);
const utils = {
    tipsOption:function (code,status,msg){
        console.log(code,status,msg);
        if (code===0&&status===200){
            message.success(msg);
            return false;
        }else if ((code===1&&status===401) || (code===2&&status===400) || (code===5&&status===405) || (code===3&&status===401)){
            message.warning(msg)
        }else if(code===5&&status===500){
            message.error(msg)
        }
            return true;
    },
    isNoLogin:function (code,status) {
        console.log(code, status);
        return code === 3 && status === 401;
    },
    isNoRole:function (code,status){
        console.log(code, status);
        return code === 4 && status === 403;
    },
    utilMessage:function (type,msg){
        if (type==='success') message.success(msg);
        if (type==='info') message.info(msg);
        if (type==='error') message.error(msg);
        if (type==='warning') message.warning(msg);
        if (type==='loading') message.loading(msg);
    },
    readerBank:async function(){
        let result;
        await axios.get("/bank/selectBanks").then((res)=>{
            const data=res.data;
            if (data.code>0){
                this.tipsOption(data.code,data.status,data.error);
                return;
            }
            result=data.data;
        })
        return result;
    },
    dataUtil:function formatDate(time){
        var date = new Date(time);
        var year = date.getFullYear(),
            month = date.getMonth() + 1,//月份是从0开始的
            day = date.getDate(),
            hour = date.getHours(),
            min = date.getMinutes(),
            sec = date.getSeconds();
        var newTime = year + '-' +
            month + '-' +
            day + ' ' +
            hour + ':' +
            min + ':' +
            sec;
        return newTime;
    }
}

export default utils;